Skip to content

Commit a064075

Browse files
authored
ensure question_classifier task is idempotent (#6674)
1 parent 4064826 commit a064075

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

kitsune/questions/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,21 @@ def flag_question(
153153
reason: str = FlaggedObject.REASON_CONTENT_MODERATION,
154154
) -> None:
155155
content_type = ContentType.objects.get_for_model(question)
156-
FlaggedObject.objects.create(
156+
flagged_object, created = FlaggedObject.objects.get_or_create(
157157
content_type=content_type,
158158
object_id=question.id,
159159
creator=by_user,
160-
status=status,
161-
reason=reason,
162-
notes=notes,
160+
defaults=dict(
161+
reason=reason,
162+
status=status,
163+
notes=notes,
164+
),
163165
)
166+
if not created:
167+
flagged_object.reason = reason
168+
flagged_object.status = status
169+
flagged_object.notes = notes
170+
flagged_object.save()
164171

165172

166173
def process_classification_result(

0 commit comments

Comments
 (0)